﻿# 0.总账户信息
account_list = [
    {'name': 'zhangsan', 'password': 111111, 'money': 100},
    {'name': 'lisi', 'password': 222222, 'money': 200},
    {'name': 'wangwu', 'password': 333333, 'money': 300},
]

# 1.显示个人账户信息
def show_account(name):
    # 遍历总账户信息
    for i, account_dict in enumerate(account_list):
        # 找到个人账户信息
        if account_dict['name'] == name:
            print('当前余额：', account_dict['money'])
            print('=' * 30)
# 2.取钱
def withdraw_account(name):
    # 遍历总账户信息
    for i, account_dict in enumerate(account_list):
        # 找到个人账户信息
        if account_dict['name'] == name:
            print('当前余额：', account_dict['money'])
            drawMoney = int(input('请输入取现金额:'))
            # 取钱金额＞账户余额，要求重新输入
            while drawMoney > account_dict['money']:
                print('当前帐户金额不足')
                drawMoney = int(input('请重新输入取现金额:'))
            account_dict['money'] = account_dict['money'] - drawMoney
            print('您已取出：', drawMoney)
            print('当前账户余额：',account_dict['money'])
            print('=' * 30)

# 3.存钱
def deposite_account(name):
    # 遍历总账户信息
    for i, account_dict in enumerate(account_list):
        # 找到个人账户信息
        if account_dict['name'] == name:
            print('当前余额：', account_dict['money'])
            depositeMoney = int(input('请输入存取金额:'))
            account_dict['money'] = account_dict['money'] + depositeMoney
            print('您已存入：', depositeMoney)
            print('当前账户余额：',account_dict['money'])
            print('='*30)
# 4.退出
def logOut():
    pass

#5. 登陆
def logIn(name):
    # 遍历账户信息，查询是否存在该账户，存在返回1，不存在返回0
    for i, account_dict in enumerate(account_list):
        if account_dict['name'] == name:
            state = 1
        else:
            state = 0
    return state


while True:
    name = input('请输入用户名：')
    password = input('请输入密码：')
    # 确认是否存在该账户，存在则登陆，不存在要求重新输入
    while logIn(name) != 1:
        print('未找到改用户，请重新输入')
        name = input('请输入用户名：')
        password = input('请输入密码：')
    # 登陆后执行的后续操作
    for i, account_dict in enumerate(account_list):
        if account_dict['name'] == name:
            print('='*12, 'ATM', '='*13)
            print('{:<1}{:<13}{:<15}'.format('   ', '1. 账户查询', '2. 取钱'))
            print('{:<1}{:<13}{:<15}'.format('   ', '3. 存钱', '4. 退出'))
            print('='*30)
            while True:
                key = input('请输入如对应的选择：')
                if key == '1':
                    show_account(name)
                elif key == '2':
                    withdraw_account(name)
                elif key == '3':
                    deposite_account(name)
                elif key == '4':
                    logOut()
                    print('='*12, '再见', '='*13)
                    break